<?php
/**
 * 支付入口
 *
 *
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');

class paymentControl extends BaseHomeControl
{
    /**
     * 首页
     */
    public function indexOp(){
        $study_id = $_GET['study_id'];
//		if(!empty($study_id)){
				$payment_id = empty($_POST) ? 0 : intval ( $_POST ['payment_id'] );
//		$study_id = $_GET['study_id'];
		//判断是否购买课程
		if(!empty($study_id)){
		if ($payment_id <= 0) {
			showMessage ( '缺少参数', SiteUrl . '/index.php?act=order&op=order_pay' . $param, 'html', 'error' );
		}
		// 支付到平台
		$payment_model = new gold_paymentModel ();
		$condition = array ();
		$condition ['payment_id'] = $payment_id;
		$payment_info = $payment_model->getRow ( $payment_id );
		
		/**
		 * 创建订单对象
		 */
		$order = new orderModel ();
		$allamount = universityModel::getstudy_price($study_id);//视频价格
		foreach ( $order_ids as $key => $value ) {
//			/**
//			 * 刷新订单数据
//			 */
			$order_info = $order->getOrderById ( intval ( $value ) );
			if (empty ( $order_info ) or ! is_array ( $order_info )) {
				showMessage ( Language::get ( 'payment_index_order' ) . $order_info ['order_sn'] . Language::get ( 'payment_index_refresh_fail' ), SiteUrl . '/index.php?act=member&op=order', 'html', 'error' );
			}
			$orderpred [] = $order_info;
//			$allamount += $order_info ['order_amount'];
		}
		
		if ($payment_info ['payment_online'] == '1' && $order_info ['payment_code'] != 'predeposit') { // 线上支付处理
			/**
			 * *********支付到预存款开始*************
			 */
			// 判断支付方式是否是预存款
			
			$payment_sel = $order_info ['payment_code'];
			// 获取支付方式信息
			$payment_id = $_POST['payment_id'];
			//查询在线支付平台名称
			
			$payment_code = predepositModel::getPayname($payment_id);
			$sql = "SELECT * FROM #__gold_payment WHERE payment_id='$payment_id' and payment_state='1'";
			$payment_info = db::queryRow ( $sql );
			if (! $payment_info) {
				showMessage ( "支付方式错误", '', 'html', 'error' );
			}
			// 预存款实例
			$member_name = memberModel::getMember_name($_SESSION['member_id']);
			$predeposit_price = $is_balancepay ? ($allamount - $member_balance) : $allamount;
			$price = floatval ( $predeposit_price );
			$insert_arr = array();
			$insert_log = array();
			$insert_arr ['pdr_sn'] = $pdr_sn = predepositModel::recharge_snOrder ();
			$insert_arr ['pdr_memberid'] = $_SESSION ['member_id'];
			$insert_arr ['pdr_membername'] = $_SESSION ['member_name'];
			$insert_arr ['pdr_price'] = $price;
			$insert_arr ['pdr_payment'] = $payment_code;
			if ($payment_sel == 'offline') {
				$insert_arr ['pdr_remittancename'] = $_POST ['huikuan_name'];
				$insert_arr ['pdr_remittancebank'] = $_POST ['huikuan_bank'];
				$insert_arr ['pdr_remittancedate'] = strtotime ( $_POST ['huikuan_date'] );
			} else {
				$insert_arr ['pdr_remittancename'] = '';
				$insert_arr ['pdr_remittancebank'] = '';
				$insert_arr ['pdr_remittancedate'] = '';
			}
			$insert_arr ['pdr_memberremark'] = $_POST ['memberremark'];
			$insert_arr ['pdr_addtime'] = time ();
			$insert_arr ['pdr_paystate'] = 0;
			$insert_arr ['pdr_study_id'] = $study_id;
			$insert_arr ['pdr_use'] = 4;
			$state = Db::insert ( 'predeposit_recharge', $insert_arr );
			
			db::delete ( 'predeposit_recharge_order', "pdr_sn='$pdr_sn'" );
			foreach ( $orderpred as $odr_info ) {
				$pro_row = array ();
				$pro_row ['pdr_id'] = $pdr_id = $state;
				$pro_row ['pdr_sn'] = $pdr_sn;
				$pro_row ['pdr_order_id'] = $odr_info ['order_id'];
				$pro_row ['pdr_order_sn'] = $odr_info ['order_sn'];
				$pro_row ['pdr_order_seller_id'] = $odr_info ['seller_id'];
				$pro_row ['pdr_order_store_id'] = $odr_info ['store_id'];
				$pro_row ['pdr_order_buyer_id'] = $odr_info ['buyer_id'];
				$pro_row ['pdr_order_buyer_name'] = $odr_info ['buyer_name'];
				$pro_row ['pdr_order_amount'] = $odr_info ['order_amount'];
				$pro_row ['pdr_order_state'] = PDR_ORDER_STATE_UNPAID;
				Db::insert ( 'predeposit_recharge_order', $pro_row );
			}
			if ($state) {
				// 使用在线支付时跳转到对应的网站
				$payment_orderinfo = array ();
				$payment_orderinfo ['order_sn'] = $insert_arr ['pdr_sn'];
				$payment_orderinfo ['order_desc'] = Language::get ( 'predeposit_recharge_paydesc' );
				$payment_orderinfo ['order_amount'] = $price;
				$payment_orderinfo ['discount'] = 0;
				$payment_orderinfo ['modeltype'] = '3'; // 表示是预存款功能调用支付接口
				/**
				 * 建立接口模型的实例对象
				 * 获得支付的url或者表单 数据
				 */
				$payment_info ['payment_config'] = unserialize ( $payment_info ['payment_config'] );
				$inc_file = BasePath . DS . 'api' . DS . 'gold_payment' . DS . $payment_info ['payment_code'] . DS . $payment_info ['payment_code'] . '.php';
				require_once ($inc_file);
				$payment_api = new $payment_info ['payment_code'] ( $payment_info, $payment_orderinfo );
				$payment_api->pay_submit ();
			} else {
				showMessage ( "冲值失败", '', 'html', 'error' );
			}
		/**
		 * *********支付到预存款结束*************
		 */
		} else { // 线下支付处理
			if ($payment_info ['payment_code'] == 'offline') {
				$this->offline_pay ( $order_info );
			} elseif ($payment_info ['payment_code'] == 'predeposit') {
			    if($is_alliance_pay) $this->alliance_predeposit_pay($orderpred);
				else $this->predeposit_pay ( $orderpred );
			} elseif ($payment_info ['payment_code'] == 'cod') {
				$this->cod_pay ( $order_info );
			} else {
				showMessage ( Language::get ( 'payment_index_store_not_support' ), SiteUrl . '/index.php?act=member&op=order', 'html', 'error' );
			}
		}
		}else{
		
        //验证支付方式
        $payment_id = intval($_POST['payment_id']);
        $order_ids=array();
        if(is_array($_GET['order_id'])){
            $order_ids=$_GET['order_id'];
        }else{
            $order_ids[]=$_GET['order_id'];
        }
        $param='';
        foreach($order_ids as $o_id){
            $param.='&order_id='.$o_id;
        }
        
        //判断是否为品牌余额支付
        $is_alliance_pay = $_POST['alliance_pay'] == 1 ? true : false;
        if($is_alliance_pay){
            $payment_model = new gold_paymentModel ();
            $predeposit_payment =  $payment_model->getRowByCode( 'predeposit' );
            $payment_id = $predeposit_payment['payment_id'];
        }
        
        //判断是否为余额支付
        $is_balancepay = empty($_POST['is_balancepay']) ? 0 : intval($_POST['is_balancepay']);
        
        if($is_balancepay){
        
            //获取订单总价
            $order_total = 0;
            $orderModel = new orderModel();
            $order_condition['buyer_id'] = $_SESSION['member_id'];
            $order_condition['order_state'] = '10';
        
            foreach($order_ids as $oid){
                $oinfo = $orderModel->getOrderById($oid, 'simple', $order_condition);
                if(!empty($oinfo))
                    $order_total += $oinfo['order_amount'];
            }
        
            //获取可用余额
            $member_balance = 0;
            $memberModel = new memberModel();
            $member_param['member_id'] = $_SESSION['member_id'];
            $minfo = $memberModel->infoMember($member_param, 'available_predeposit');
            $member_balance = $minfo['available_predeposit'];
        
            //若余额足够支付订单，payment_id设置为预存款ID
            if($member_balance >= $order_total){
                $payment_model = new gold_paymentModel ();
                $predeposit_payment =  $payment_model->getRowByCode( 'predeposit' );
                $payment_id = $predeposit_payment['payment_id'];
            }
        
            if ($payment_id <= 0 ) {
                showMessage ( '请选择一种付款方式支付剩余金额' , '/index.php?act=order&op=order_pay' . $param, 'html', 'error' );
            }
        }        
                
        if($payment_id <= 0){
            showMessage('缺少参数','index.php?act=order&op=order_pay'.$param);
        }
        
        //支付到平台
        $payment_model =new gold_paymentModel();
        $condition = array();
        $condition['payment_id'] = $payment_id;
        $payment_info = $payment_model->getRow($payment_id);

        //商城存在该支付方式并且启用
        if (empty($payment_info) || $payment_info['payment_state'] != 1){
            showMessage('商城不支持该支付方式','index.php?act=order&op=order_pay'.$param);
        }
        
        //根据code验证支付方式在管理员后台是否启用
        if(!$payment_model->checkPayment($payment_info['payment_code'])){
            showMessage('系统不支持指定的支付方式'.$payment_info['payment_code'],'index.php?act=order&op=order_pay&order_id='.$param);
        }

        /**
         * 创建订单对象
         */
        $order =new orderModel();
        foreach ($order_ids as $key => $value) {
            /**
             * 根据订单标号读取支付方式的code(取得该订单的全部数据)
             */
            $order_info	= $order->getOrderById(intval($value));
            /**
             * 订单数据非空判断
             */
            if(empty($order_info) or !is_array($order_info)){
                showMessage('订单不存在','index.php?act=member_order');
            }
            /**
             * 验证订单编号与当前的登录用户是否对应
             */
            if($_SESSION['member_id'] != $order_info['buyer_id']){
                showMessage('订单'.$order_info['order_sn'].'不存在','index.php?act=member_order');
            }
            /**
             * 订单状态必须是0值的判断
             */
            if($order_info['order_state'] != '10'){
                showMessage('订单'.$order_info['order_sn'].'已经支付完毕','index.php?act=member_order');//'已经支付完毕'
            }
            /**
             * 更新订单支付方式
             */
            $input	= array();
            if($payment_info['payment_code'] == 'cod') $input['order_state'] = 15;
            $input['payment_id']	= $payment_id;
            $input['payment_name']	= $payment_info['payment_name'];
            $input['payment_code']	= $payment_info['payment_code'];
            if(!$order->updateOrder($input,intval($value))){
                showMessage('为订单添加支付信息失败','index.php?act=member_order');
            }
        }

        $allamount=0;
        foreach ($order_ids as $key => $value) {
            /**
             * 刷新订单数据
             */
            $order_info	= $order->getOrderById(intval($value));
            if(empty($order_info) or !is_array($order_info)){
                showMessage('订单'.$order_info['order_sn'].'刷新失败','index.php?act=member_order');
            }
            $orderpred[]=$order_info;
            $allamount+=$order_info['order_amount'];
        }

        /**
         * 根据支付方式的线上/线下属性,分支处理
         */
        if($payment_info['payment_online']=='1' && $order_info['payment_code'] != 'predeposit'){//线上支付处理
            /**
             * 建立接口模型的实例对象
             * 获得支付的url或者表单 数据
             */

            /***********支付到预存款开始**************/
            //判断支付方式是否是预存款
            $payment_sel = $order_info['payment_code'];
            //获取支付方式信息
            $sql="SELECT * FROM #__gold_payment WHERE payment_code='$payment_sel' and payment_state='1'";
            $payment_info =db::queryRow($sql);
            if (!$payment_info){
                showMessage("支付方式错误");
            }
            //预存款实例
            $predeposit_price = $is_balancepay ? ($allamount - $member_balance) : $allamount;
            $price = floatval ( $predeposit_price );
            $insert_arr = array();
            $insert_arr['pdr_sn'] =$pdr_sn=predepositModel::recharge_snOrder();
            $insert_arr['pdr_memberid'] = $_SESSION['member_id'];
            $insert_arr['pdr_membername'] = $_SESSION['member_name'];
            $insert_arr['pdr_price'] = $price;
            $insert_arr['pdr_payment'] = $payment_sel;
            if ($payment_sel == 'offline'){
                $insert_arr['pdr_remittancename'] = $_POST['huikuan_name'];
                $insert_arr['pdr_remittancebank'] = $_POST['huikuan_bank'];
                $insert_arr['pdr_remittancedate'] = strtotime($_POST['huikuan_date']);
            } else {
                $insert_arr['pdr_remittancename'] = '';
                $insert_arr['pdr_remittancebank'] = '';
                $insert_arr['pdr_remittancedate'] = '';
            }
            $insert_arr['pdr_memberremark'] = $_POST['memberremark'];
            $insert_arr['pdr_addtime'] = time();
            $insert_arr['pdr_paystate'] = 0;
            $insert_arr['pdr_use']=PDR_USE_ORDER;
            $state = Db::insert('predeposit_recharge',$insert_arr);
			
			db::delete('predeposit_recharge_order',"pdr_sn='$pdr_sn'");
            foreach($orderpred as $odr_info){
                $pro_row=array();
                $pro_row['pdr_id']=$pdr_id=$state;
                $pro_row['pdr_sn']=$pdr_sn;
                $pro_row['pdr_order_id']=$odr_info['order_id'];
                $pro_row['pdr_order_sn']=$odr_info['order_sn'];
                $pro_row['pdr_order_seller_id']=$odr_info['seller_id'];
                $pro_row['pdr_order_store_id']=$odr_info['store_id'];
                $pro_row['pdr_order_buyer_id']=$odr_info['buyer_id'];
                $pro_row['pdr_order_buyer_name']=$odr_info['buyer_name'];
                $pro_row['pdr_order_amount']=$odr_info['order_amount'];
                $pro_row['pdr_order_state']=PDR_ORDER_STATE_UNPAID;
                Db::insert('predeposit_recharge_order',$pro_row);
            }

            if($state) {
                //使用在线支付时跳转到对应的网站
                $payment_orderinfo = array();
                $payment_orderinfo['order_sn']      = $insert_arr['pdr_sn'];
                $payment_orderinfo['order_desc']    = '预存款充值订单';
                $payment_orderinfo['order_amount']  = $price;
                $payment_orderinfo['discount']		= 0;
                $payment_orderinfo['modeltype']		= '3';//表示是预存款功能调用支付接口
                /**
                 * 建立接口模型的实例对象
                 * 获得支付的url或者表单 数据
                 */
                $payment_info['payment_config'] = unserialize($payment_info['payment_config']);
                $inc_file = BasePath.DS.'api'.DS.'gold_payment'.DS.$payment_info['payment_code'].DS.$payment_info['payment_code'].'.php';
                require_once($inc_file);
                $payment_api = new $payment_info['payment_code']($payment_info,$payment_orderinfo);
                $payment_api->pay_submit();
            } else {	
                showMessage("冲值失败");
            }
            /***********支付到预存款结束**************/
        }else{

            if ($payment_info['payment_code'] == 'offline')
                $this->offline_pay($order_info);
            
            elseif ($payment_info['payment_code'] == 'predeposit')
			    $is_alliance_pay ? $this->alliance_predeposit_pay($orderpred) : $this->predeposit_pay ( $orderpred );
            
            elseif ($payment_info['payment_code'] == 'cod')
                $this->cod_pay($order_info);
            
            else 
                showMessage('商城不支持该支付方式','index.php?act=member_order');
        }
    }
    }

    /**
     * 线下支付
     *
     */
    public function offline_pay($order_info)
    {
        $order = new orderModel();
        $input = array();
        $input['order_state'] = $order_info['order_state'] == 50 ? 50 : 10;
        $input['pay_message'] = serialize($this->stripslashes_deep($_POST['offline']));
        $input['payment_time'] = TIMESTAMP;
        if ($order->updateOrder($input, intval($order_info['order_id']))) {
            /**
             * 发送邮件通知
             */
            $member_model = new memberModel();
            $seller = $member_model->infoMember(array('member_id' => $order_info['seller_id']));
            $param = array(
                'site_url' => SiteUrl,
                'site_name' => $GLOBALS['setting_config']['site_name'],
                'buyer_name' => $order_info['buyer_name'],
                'seller_name' => $seller['member_name'],
                'order_sn' => $order_info['order_sn'],
                'order_id' => intval($order_info['order_id']),
                'pay_message' => trim($_POST['pay_message'])
            );
            noticeModel::system_send_notice($order_info['seller_id'], 'email_toseller_offline_pay_notify', $param);
            showMessage('订单处理成功','index.php?act=member_order');
        } else {
            showMessage('订单处理超时','index.php?act=member_order');
        }
    }

    /**
     * 递归去除转义
     *
     * @param array /string $value
     * @return array/string
     */
    public function stripslashes_deep($value)
    {
        $value = is_array($value) ? array_map(array($this, 'stripslashes_deep'), $value) : stripslashes($value);
        return $value;
    }

    /**
     * 预存款支付
     *
     */
    public function predeposit_pay($orss){
        //验证订单信息
        $order	=new orderModel();
        $member_model	=new memberModel();
        $predeposit_model =new predepositModel();
        //验证订单是否已经支付
        //冻结买家账户预存款
        $buyer_info	= $member_model->infoMember(array('member_id'=>$_SESSION['member_id']));
        if (!is_array($buyer_info) || count($buyer_info)<=0){
            showMessage('买家信息错误','index.php?act=member_order');
        }
        $pay_amount=0;
        foreach ($orss as $order_info) {
            if ($order_info['order_state'] != 10){//未支付时
                showMessage('支付编号为'.$order_info['order_sn'].'已经支付完毕','index.php?act=member_order');
            }
            $pay_amount+=$order_info['order_amount'];
        }
        //预存款是否足够
        if (floatval($buyer_info['available_predeposit']) < $pay_amount){
            $pay_price=$pay_amount-floatval($buyer_info['available_predeposit']);
            showMessage('预存款余额不足，请充值');
        }

        //========================
        foreach ($orss as $order_info) {
            if ($order_info['order_state'] != 10){//未支付时
                showMessage('支付编号为'.$order_info['order_sn'].'已经支付完毕','index.php?act=member_order');
            }
            //冻结买家账户预存款

            $buyer_info	= $member_model->infoMember(array('member_id'=>$_SESSION['member_id']));
            if (!is_array($buyer_info) || count($buyer_info)<=0){
                showMessage('支付编号为'.$order_info['order_sn'].'会员信息错误','index.php?act=member_order');
            }
            //预存款是否足够
            if (floatval($buyer_info['available_predeposit']) < $order_info['order_amount']){
                showMessage('预存款余额不足，请充值');
            }

            //减少可用金额
            $log_arr = array();
            $log_arr['memberid'] = $_SESSION['member_id'];
            $log_arr['membername'] = $_SESSION['member_name'];
            $log_arr['logtype'] = '0';
            $log_arr['price'] = -$order_info['order_amount'];
            $log_arr['desc'] = '订单'.$order_info['order_sn'].'消费减少预存款可用金额';
            $predeposit_model->savePredepositLog('order',$log_arr);
            //增加冻结金额
            $log_arr['logtype'] = '1';
            $log_arr['price'] = $order_info['order_amount'];
            $log_arr['desc'] = '订单'.$order_info['order_sn'].'消费增加预存款冻结金额';
            $predeposit_model->savePredepositLog('order',$log_arr);
            unset($log_arr);

            //修改订单信息
            $input	= array();
            $input['order_cod']	= 0; //在线付款设置货到付款订单为在线付款
            $input['order_paid']	= 1;
            $input['order_state']	= 20; //已付款
            $input['pay_message']	= trim($_POST['pay_message']);
            $input['payment_time']	= time();
            $result = $order->updateOrder($input,intval($order_info['order_id']));
            if($result){
                //增加订单日志
                orderModel::addLogOrder('20',intval($order_info['order_id']));
                /**
                 * 发送邮件通知
                 */
                $member_model	=new memberModel();
                $seller	= $member_model->infoMember(array('member_id'=>$order_info['seller_id']));
                $param	= array(
                    'site_url'	=> SiteUrl,
                    'site_name'	=> $GLOBALS['setting_config']['site_name'],
                    'buyer_name'	=> $order_info['buyer_name'],
                    'seller_name'	=> $seller['member_name'],
                    'order_sn'	=> $order_info['order_sn'],
                    'order_id'	=> intval($order_info['order_id']),
                    'pay_message'	=> trim($_POST['pay_message'])
                );
                noticeModel::system_send_notice($order_info['seller_id'],'email_toseller_online_pay_success_notify',$param);
                $success='1';
				mc_agentModel::memberToAgent(intval($order_info['order_id']));
                $sql = "SELECT xjq_id FROM #__order WHERE order_id = '{$order_info ['order_id']}'";
                $xjq_id = Db::queryOne($sql);
                if($xjq_id == 0){
                   /* 赠送积分开始 */
                    pointsModel::givePointsByOrderID($order_info ['order_id']);
                    /* 赠送积分结束 */
                 }
            }else{
                showMessage('订单处理超时',"index.php?act=member_order");
            }

        }
        if ($success=='1') {
            //双十活动
            $special_activityModel = new special_activityModel();
            $special_activityModel->doubleTen2k15($pay_amount);            
            showMessage('订单处理成功',"index.php?act=member_order");
        }
    }


    /**
     * 货到付款
     *
     */
    public function cod_pay($order_info)
    {
        $order = new orderModel();
        $input = array();
        /*$input['pay_message'] = trim($_POST['pay_message']);
        $input['payment_time'] = time();*/
		$input['order_cod'] = 1;
        if ($order->updateOrder($input, intval($order_info['order_id']))) {
			mc_agentModel::memberToAgent(intval($order_info['order_id']));
           $sql = "SELECT xjq_id FROM #__order WHERE order_id = '{$order_info ['order_id']}'";
            $xjq_id = Db::queryOne($sql);
            if($xjq_id == 0){
               /* 赠送积分开始 */
                pointsModel::givePointsByOrderID($order_info ['order_id']);
                /* 赠送积分结束 */
             }
            showMessage('订单处理成功',"index.php?act=member_order");
        } else {
            showMessage('订单处理超时',"index.php?act=member_order");
        }
    }


    /**
     * 支付成功
     *
     */
    public function payment_successOp()
    {
        $url = "index.php?act=member_order";

        showMessage('订单处理成功', $url);
    }

    /**
     * @desc 品牌加盟预存款支付
     */
    public function alliance_predeposit_pay($orss) {
    
        Language::read ( 'home_payment_index' );
        // 验证订单信息
        $order = new orderModel ();
        $member_model = new memberModel ();
        $brand_alliance_model = new brand_allianceModel();
        $use_alliance_bond = (bool)$_POST['use_alliance_bond'];
        // 验证订单是否已经支付 ，冻结买家账户预存款
        foreach ( $orss as $order_info ) {
    
            //未支付时
            if ($order_info ['order_state'] != 10) {
                showMessage ( '支付编号为' . $order_info ['order_sn'] . Language::get ( 'payment_index_pay_finish' ), 'index.php?act=member_order', 'html', 'error' );
            }
    
            if(empty($order_info['brand_id'])){
                showMessage ( '支付编号为' . $order_info ['order_sn'] . '不是品牌加盟订单', 'index.php?act=member_order', 'html', 'error' );
            }
    
            //校验买家信息
            $buyer_info = Db::queryRow("select * from #__brand_alliance where member_id = {$_SESSION['member_id']} and brand_id = {$order_info['brand_id']}");
    
            if (! is_array ( $buyer_info ) || count ( $buyer_info ) <= 0) {
                showMessage ( '支付编号为' . $order_info ['order_sn'] . Language::get ( 'payment_index_buyerinfo_error' ), 'index.php?act=member_order', 'html', 'error' );
            }
    
            // 预存款是否足够
            $available_predeposit = $use_alliance_bond ? $buyer_info ['available_deposit'] + $buyer_info['bond'] : $buyer_info['available_deposit'];
    
            if (floatval ( $available_predeposit ) < $order_info ['order_amount']) {
                showMessage ( '品牌加盟预存款余额不足，请充值', 'index.php?act=brand_alliance&op=brand_pay&brand_id='.$buyer_info['brand_id'], 'html', 'error' );
            }
    
            // 订单消费记录
            $log_arr = array ();
            $log_arr ['bdlog_memberid'] = $_SESSION ['member_id'];
            $log_arr ['bdlog_membername'] = $_SESSION ['member_name'];
            $log_arr ['bdlog_brandid'] = $order_info['brand_id'];
            $log_arr ['order_amount'] = $order_info['order_amount'];
            $log_arr ['order_sn'] = $order_info['order_sn'];
            $log_arr ['use_alliance_bond'] = $use_alliance_bond;
            $log_arr ['available_deposit'] = $buyer_info['available_deposit'];
            $log_arr ['frozen_deposit'] = $buyer_info['frozen_deposit'];
            $log_arr ['available_bond'] = $buyer_info['bond'];
            $brand_alliance_model->saveAllianceOrderPredepositLog ($log_arr );
            unset ( $log_arr );
    
            // 修改订单信息
            $input = array ();
            $input ['order_cod'] = 0; // 在线付款设置货到付款订单为在线付款
            $input ['order_paid'] = 1;
            $input ['order_state'] = 20; // 已付款
            $input ['pay_message'] = trim ( $_POST ['pay_message'] );
            $input ['payment_time'] = time ();
            $result = $order->updateOrder ( $input, intval ( $order_info ['order_id'] ) );
            goodsModel::reduceGoodsStock($order_info['order_id']);
            if ($result) {
                // 增加订单日志
                orderModel::addLogOrder ( '20', intval ( $order_info ['order_id'] ) );
                /**
                 * 发送邮件通知
                */
                $member_model = new memberModel ();
                $seller = $member_model->infoMember ( array (
                    'member_id' => $order_info ['seller_id']
                ) );
                $param = array (
                    'site_url' => SiteUrl,
                    'site_name' => $GLOBALS ['setting_config'] ['site_name'],
                    'buyer_name' => $order_info ['buyer_name'],
                    'seller_name' => $seller ['member_name'],
                    'order_sn' => $order_info ['order_sn'],
                    'order_id' => intval ( $order_info ['order_id'] ),
                    'pay_message' => trim ( $_POST ['pay_message'] )
                );
                noticeModel::system_send_notice ( $order_info ['seller_id'], 'email_toseller_online_pay_success_notify', $param );
                $success = '1';
                mc_agentModel::memberToAgent ( intval ( $order_info ['order_id'] ) );
                /* 赠送积分开始 */
                pointsModel::givePointsByOrderID($order_info ['order_id']);
                /* 赠送积分结束 */
            } else {
                showMessage ( '订单处理超时', "index.php?act=member_order", 'html', 'error' );
            }
        }
        if ($success == '1') {
            showMessage ( '订单处理成功', "index.php?act=member_order" );
        }
    }
    
}